﻿using System;
using System.Text;
using Token.Piker.BLL;

namespace Token.Piker.Web.Admin.Activity
{
    public partial class List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            StringBuilder strWhere = new StringBuilder();
            if (txtKeyword.Text.Trim() != "")
            {
                strWhere.AppendFormat("Theme like '%{0}%'", txtKeyword.Text.Trim());
            }

            ActivityBLL bll = new ActivityBLL();
            if (pagerList.CurrentPageIndex == 1)
            {
                gridView.DataSource = bll.GetList(pagerList.PageSize, strWhere.ToString(), "StartTime DESC");
            }
            else
            {
                gridView.DataSource = bll.GetListByPage(strWhere.ToString(), "StartTime DESC", pagerList.StartRecordIndex, pagerList.EndRecordIndex);
            }
            gridView.DataBind();
            pagerList.RecordCount = bll.GetRecordCount(strWhere.ToString());
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void pagerList_PageChanged(object sender, EventArgs e)
        {
            if (!IsPostBack && !IsCallback)
            {
                BindData();
            }
        }

        protected string GetAdderName(object adderID)
        {
            if (adderID == null)
            {
                return string.Empty;
            }
            AdminBLL adminBLL = new AdminBLL();
            int adminID = Convert.ToInt32(adderID);
            Token.Piker.Model.Admin admin = adminBLL.GetModel(adminID);
            return admin.RealName;
        }
    }
}